var e = require("../../@babel/runtime/helpers/interopRequireDefault").default, t = e(require("../../kta/index")), a = e(require("../../api/api_YQYL.js")), i = e(require("../../api/auth")), o = require("../../config/Links"), s = require("../../utils/YQYL"), n = [ null, "uncomplete", "complete", "failure" ], r = 1, c = getApp();

t.default.Page({
    data: {
        scrollHeight: 550,
        check_id_card: !1,
        shareUrl: "",
        imgBaseUrl: o.imageBaseUrl.YQYL,
        tabIndex: "1",
        spread_record_list: [],
        showList: [],
        red_packet_daily_limit: !1,
        modal: !1,
        cancelText: "",
        modalText: "",
        showPoster: !1,
        poster: null,
        postUtil: {
            handleSharePoster: function() {}
        }
    },
    onShareAppMessage: function() {
        return (0, s.handleShare)(this, "recordSpread");
    },
    onLoad: function(e) {
        var t = wx.getSystemInfoSync().windowHeight;
        this.setData({
            scrollHeight: t - 50
        }), (0, s.initPage)(this, e, "spreadRecord");
    },
    onShow: function() {
        this.fetchList();
    },
    fetchList: function() {
        var e = this;
        wx.showLoading({
            title: "加载中"
        }), a.default.getSpreadRecordList(r, n[this.data.tabIndex]).then(function(t) {
            var a = t.result, i = a.check_id_card, o = a.spread_record_list, s = a.red_packet_daily_limit, n = "2" === e.data.tabIndex ? 15 : 13;
            o.forEach(function(e) {
                e.spread_desc1 = e.spread_desc.slice(0, -1 * n), e.spread_desc2 = e.spread_desc.slice(-1 * n);
            }), e.setData({
                check_id_card: i,
                red_packet_daily_limit: s,
                spread_record_list: o,
                showList: o.slice(0, 10 * r)
            });
        }).finally(function() {
            wx.hideLoading();
        });
    },
    loadMore: function() {
        10 * r < this.data.spread_record_list.length && (r++, this.setData({
            showList: this.data.spread_record_list.slice(0, 10 * r)
        }));
    },
    changeTab: function(e) {
        var t = this, a = e.currentTarget.dataset.index;
        r = 1, this.setData({
            tabIndex: a
        }, function() {
            t.fetchList();
        });
    },
    handlePoster: function() {
        this.data.poster ? this.setData({
            showPoster: !0
        }) : this.data.postUtil.handleSharePoster("record");
    },
    showModal: function(e) {
        var t = this, i = e.currentTarget.dataset.type;
        if ("illegal" === i) wx.showModal({
            content: "订单信息发生变更，无法领取红包，敬请谅解",
            showCancel: !1,
            confirmText: "确定"
        }); else if ("illegal2" === i) wx.showModal({
            content: "微信红包发放后的24小时内未领取。已超时退回",
            showCancel: !1,
            confirmText: "确定"
        }); else if (this.data.red_packet_daily_limit) wx.showModal({
            content: "单用户单日领取红包个数限额10个，请于次日领取",
            showCancel: !1,
            confirmText: "确定"
        }); else if ("charge" === i) {
            var o = e.currentTarget.dataset.seq;
            this.checkValid() && a.default.getSpreadHongBao(o).then(function() {
                wx.showModal({
                    content: "红包将通过“王卡助手”微信公众号发放，请您留意公众号消息",
                    showCancel: !1,
                    confirmText: "知道啦"
                }), t.fetchList();
            }).catch(function() {
                wx.showModal({
                    content: "微信异常，红包发放失败",
                    showCancel: !1,
                    confirmText: "确定"
                });
            });
        }
    },
    checkValid: function() {
        return !!this.data.check_id_card || (c.globalData.phone ? wx.navigateTo({
            url: "/pages/YQYL_register/index?adtag=" + c.globalData.aucChannel
        }) : this.setData({
            modal: !0,
            modalText: "手机号码获取失败，无法领取红包!",
            modalType: "phone"
        }), !1);
    },
    getPhoneNumber: function(e) {
        this.setData({
            modal: !1,
            modalText: "",
            modalType: ""
        }), i.default.auth({
            encryptedData: e.detail.encryptedData,
            iv: e.detail.iv,
            source: 2
        }).then(function(e) {
            c.globalData.phone = e.data.phone, wx.navigateTo({
                url: "/pages/YQYL_register/index?channel=".concat(c.globalData.aucChannel, "&adtag=").concat(c.globalData.aucChannel)
            });
        });
    },
    closeModal: function() {
        this.setData({
            modal: !1,
            modalText: ""
        });
    },
    closePoster: function() {
        this.setData({
            showPoster: !1
        });
    },
    copyKeyword: function() {
        wx.setClipboardData({
            data: "我的历史邀请记录"
        }), this.closeModal();
    }
});